﻿using System;
using System.Threading;

namespace Registration.Test.TestUtils
{
    internal static class DatabaseUtils
    {
        public static int Delay = 1000;

        public static void InitializeDatabase()
        {
            for (int i = 0; i < 30; i++)
            {
                Thread.Sleep(Delay);
            }

            using (Database d = new Database())
            {
                d.Drivers.DeleteAllOnSubmit(d.Drivers);

                foreach (var driver in GetDrivers())
                {
                    d.Drivers.InsertOnSubmit(driver);
                }


                d.SubmitChanges();
            }
        }

        public static Driver[] GetDrivers()
        {
            Driver p = new Driver
                           {
                               FirstName = "Catherine",
                               Surname = "Powell",
                               ID = "JM5555555",
                               ExpirationDate = new DateTime(2015, 5, 5),
                               Address = "123 Fake Street, Redmond, WA 98052",
                               Gender = Gender.Male,
                               Height = 2,
                               Weight = 80,
                               Eyes = Eyes.Brown,
                               PhotoPath = @"..\..\..\Registration.Test\Jason Malinowski.jpg"
                           };

            Driver p2 = new Driver
                            {
                                FirstName = "Woody",
                                Surname = "Zuill",
                                ID = "JM5555555",
                                ExpirationDate = new DateTime(2015, 5, 5),
                                Address = "123 Fake Street, Redmond, WA 98052",
                                Gender = Gender.Male,
                                Height = 2,
                                Weight = 80,
                                Eyes = Eyes.Brown,
                                PhotoPath = @"..\..\..\Registration.Test\Jason Malinowski.jpg"
                            };
            Driver p3 = new Driver
                            {
                                FirstName = "Lynn",
                                Surname = "Langit",
                                ID = "JM5555555",
                                ExpirationDate = new DateTime(2015, 5, 5),
                                Address = "123 Fake Street, Redmond, WA 98052",
                                Gender = Gender.Female,
                                Height = 2,
                                Weight = 63,
                                Eyes = Eyes.Brown,
                                PhotoPath = @"..\..\..\Registration.Test\Jason Malinowski.jpg"
                            };
            Driver p4 = new Driver
                            {
                                FirstName = "Dan",
                                Surname = "Gilkerson",
                                ID = "JM5555555",
                                ExpirationDate = new DateTime(2015, 5, 5),
                                Address = "123 Fake Street, Redmond, WA 98052",
                                Gender = Gender.Female,
                                Height = 2,
                                Weight = 63,
                                Eyes = Eyes.Brown,
                                PhotoPath = @"..\..\..\Registration.Test\Jason Malinowski.jpg"
                            };
            Driver p5 = new Driver
                            {
                                FirstName = "Jason",
                                Surname = "Malinowski",
                                ID = "JM5555555",
                                ExpirationDate = new DateTime(2015, 5, 5),
                                Address = "123 Fake Street, Redmond, WA 98052",
                                Gender = Gender.Male,
                                Height = 2,
                                Weight = 80,
                                Eyes = Eyes.Brown,
                                PhotoPath = @"..\..\..\Registration.Test\Jason Malinowski.jpg"
                            };
            return new[] {p, p2, p3, p4, p5};
        }

        public static Driver GetPrimaryUser()
        {
            return new Driver
                       {
                           FirstName = "Fred",
                           Surname = "Flintston",
                           ID = "5734HG",
                           SecondaryId = "Passort #645 453 5943",
                ExpirationDate = new DateTime(2015, 5, 5),
                Address = "123 1st Street, Bedrock, MT 98052",
                Gender = Gender.Male,
                Height = 2,
                Weight = 120,
                Eyes = Eyes.Brown
            };
        }
    }
}